﻿
namespace Byteabyte
{
    class IcsAlarm
    {
        public string Trigger { get; set; }
        public string Action { get; set; }
        public string Description { get; set; }

        internal void ParseAlarm(System.IO.StreamReader reader)
        {
            string icsLine = string.Empty;
            while ((icsLine = reader.ReadLine()) != IcsStrings.IcsEventEnd)
            {
                if (icsLine == null) break;

                ParseIcsLine(icsLine);
            }
        }

        private void ParseIcsLine(string icsLine)
        {
            var lineParts = icsLine.Split(":".ToCharArray());
            if (lineParts.Length < 2) return;
            string lineHeader = lineParts[0].ToUpper();
            string lineValue = string.Empty;
            for (int i = 1; i < lineParts.Length; i++)
            {
                lineValue += lineParts[i];
                lineValue += ":";
            }
            lineValue = lineValue.Substring(0, lineValue.Length - 1);

            switch (lineHeader)
            {
                case IcsStrings.IcsAlarmTriggerHeader:
                    {
                        Trigger = lineValue;
                        break;
                    }
                case IcsStrings.IcsAlarmActionHeader:
                    {
                        Action = lineValue;
                        break;
                    }
                case IcsStrings.IcsAlarmDescriptionHeader:
                    {
                        Description = lineValue;
                        break;
                    }
            }
        }
    }
}
